package com.xintong.visualinspection.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xintong.system.err.BusinessException;
import com.xintong.visualinspection.bean.CheckItem;
import com.xintong.visualinspection.service.CheckItemService;

/**
 * 文件名：CheckItemController
 * 版本信息：日期：2017/3/30 Copyright 江苏省交通规划设计院 Corporation 2017 版权所有.
 */
@RestController
@RequestMapping("/checkItem")
public class CheckItemController extends BaseController {

    @Autowired
    private CheckItemService checkItemService;

   
    /**
     * 添加考核项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/add")
    public String add(@Valid @RequestBody CheckItem checkItem){
    	checkItemService.insert(checkItem);
    	return super.returnSuccessResult("添加成功");
    }
    
    /**
     * 修改考核项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/update")
    public String update(@Valid @RequestBody CheckItem checkItem){
    	checkItemService.update(checkItem);
    	return super.returnSuccessResult("修改成功");
    }
    
    /**
     * 删除考核项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/delete")
    public String delete(@RequestBody CheckItem checkItem){
    	checkItemService.delete(checkItem.getId());
    	return super.returnSuccessResult("删除成功");
    }
    
    /**
     * 通过父亲id获取考核项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getByParentId")
    public String getByParentId(@RequestBody CheckItem checkItem){
    	if(checkItem.getParent_id()==null){
    		throw new BusinessException(20101);
    	}
    	List<CheckItem> checkItemList = checkItemService.getByParentId(checkItem.getParent_id());
    	return super.returnSuccessResult(checkItemList);
    }
    
    /**
     * 通过方法id获取考核项
     * @return
     * String
     * @exception
     * @since  1.0.0
     */
    @RequestMapping(value = "/getByRuleId")
    public String getByRuleId(@RequestBody CheckItem checkItem){
    	if(checkItem.getRule_id()==null){
    		throw new BusinessException(20101);
    	}
    	List<CheckItem> checkItemList = checkItemService.getByRuleId(checkItem.getRule_id());
    	return super.returnSuccessResult(checkItemList);
    }
}
